package com.sdkx.app.datalayers;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;

import com.sdkx.app.R;
import com.sdkx.app.model.WayPoint;

import java.util.ArrayList;
import java.util.List;

import cn.creable.gridgis.display.Display;
import cn.creable.gridgis.display.LineSymbol;
import cn.creable.gridgis.geometry.LineString;
import cn.creable.gridgis.geometry.Point;
import cn.creable.gridgis.util.Image;

public class AirWayLine extends MapDraw {
    List<WayPoint> wayPoints = new ArrayList<>();
    private Paint paint;
    LineSymbol lineSymbol = new LineSymbol();
    LineString line;
    Image posimg;
    public AirWayLine(Context context) {
        super(context);
        paint = new Paint();
        paint.setTextSize(25);
        paint.setColor(0xFF007C41);
        lineSymbol.setColor(0xFF007C41);
        lineSymbol.setWidth(4);
        BitmapDrawable bmpDraw = (BitmapDrawable) appContext.getResources().getDrawable(R.drawable.gps_line);
        posimg = new Image(bmpDraw.getBitmap());
    }

    @Override
    protected void draw2(Canvas canvas, Display display) {
        Display d = (Display) display;
        Canvas oldG = d.getCanvas();
        d.setCanvas(canvas);
        if(line != null){
            d.DrawPolyline(line,lineSymbol);
        }
        for(WayPoint point : wayPoints){
            d.DrawImagePoint(new Point(point.getDoubleLongitude(), point.getDoubleLatitude()), posimg);
        }
        d.setCanvas(oldG);
    }

    public List<WayPoint> getWayPoints() {
        return wayPoints;
    }

    public void setWayPoints(List<WayPoint> points) {
        if (points != null) {
            wayPoints = points;
            line = new LineString(wayPoints.size(), null);
            for (int i = 0; i < wayPoints.size(); i++) {
                WayPoint point = wayPoints.get(i);
                line.setPoint(i, new Point(point.getDoubleLongitude(), point.getDoubleLatitude()));
            }
        }
    }
}
